const compressionPlugin = require('compression-webpack-plugin')
const path = require('path')

module.exports = {
    publicPath: './',
    outputDir: 'dist',
    lintOnSave: true,
    runtimeCompiler: true,
    configureWebpack: config => {
        if (process.env.NODE_ENV == 'production') {
            return {
                plugins: [
                    new compressionPlugin({
                        test: /\.js$|\.html$|\.css/,
                        threshold: 10240,
                        deleteOriginalAssets: false //删除源文件
                    })
                ],
                externals: {}
            }
        }
    },
    chainWebpack: config => {
        config
            .resolve.alias
            .set('@', resolve('src')) //配置src目录别名
    }
}

function resolve(dir) {
    return path.join(__dirname, dir)
}